home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / NewProj.cpp < prev    next >
C/C++ Source or Header  |  2002-06-11  |  13KB  |  510 lines

  1. // NewProj.cpp : implementation file
  2. //
  3.  
  4. // pour lecture dir
  5. //#include "kernel32.h"
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. /* Externe C */
  12. extern "C" {
  13.   #include "htscore.h"
  14. }
  15.  
  16. #include "XSHBrowseForFolder.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. extern HICON httrack_icon;
  25. extern CNewProj* dialog0;
  26.  
  27. // Helper
  28. extern LaunchHelp* HtsHelper;
  29.  
  30. /* Main WizTab frame */
  31. #include "WizTab.h"
  32. extern CWizTab* this_CWizTab;
  33.  
  34. /* Main splitter frame */
  35. #include "DialogContainer.h"
  36. #include "splitter.h"
  37. extern CSplitterFrame* this_CSplitterFrame;
  38.  
  39. /* DirTreeView */
  40. #include "DirTreeView.h"
  41. extern CDirTreeView* this_DirTreeView;
  42.  
  43. /* reference sur objet Wid1 */
  44. #include "Wid1.h"
  45. extern Wid1* dialog1;
  46.  
  47. /* shellapp */
  48. extern CShellApp* CShellApp_app;
  49.  
  50. /* crΘation structure */
  51. extern "C" int structcheck(char* s);
  52.  
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CNewProj dialog
  56.  
  57. IMPLEMENT_DYNCREATE(CNewProj, CPropertyPage)
  58.  
  59. CNewProj::CNewProj()
  60.     : CPropertyPage(CNewProj::IDD)
  61. {
  62.   dialog0=this;    /* NOTER REFERENCE */
  63.   can_click_next=TRUE;
  64.     //{{AFX_DATA_INIT(CNewProj)
  65.     m_projname = _T("");
  66.     m_projpath = _T("");
  67.     //}}AFX_DATA_INIT
  68. }
  69.  
  70. CNewProj::~CNewProj() {
  71.   dialog0=NULL;
  72. }
  73.  
  74.  
  75. void CNewProj::DoDataExchange(CDataExchange* pDX)
  76. {
  77.     CPropertyPage::DoDataExchange(pDX);
  78.     //{{AFX_DATA_MAP(CNewProj)
  79.     DDX_Control(pDX, IDC_projname, m_ctl_projname);
  80.     DDX_Text(pDX, IDC_projname, m_projname);
  81.     DDX_Text(pDX, IDC_projpath, m_projpath);
  82.     //}}AFX_DATA_MAP
  83. }
  84.  
  85.  
  86. #define wm_CEasyDropTargetCallback (WM_USER + 1)
  87. BEGIN_MESSAGE_MAP(CNewProj, CPropertyPage)
  88.     //{{AFX_MSG_MAP(CNewProj)
  89.     ON_BN_CLICKED(IDC_br, Onbr)
  90.     ON_EN_CHANGE(IDC_projpath, OnChangeprojpath)
  91.     ON_CBN_EDITCHANGE(IDC_projname, OnChangeprojname)
  92.     ON_WM_CREATE()
  93.     ON_CBN_SELCHANGE(IDC_projname, OnSelchangeprojname)
  94.     //}}AFX_MSG_MAP
  95.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  96.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  97.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  98.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  99.   //
  100.   ON_MESSAGE( wm_CEasyDropTargetCallback, DragDropText)
  101. END_MESSAGE_MAP()
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CNewProj message handlers
  105.  
  106. CString CNewProj::GetBasePath() {
  107.   CString st=m_projpath;
  108.   st.Replace('/','\\');
  109.   st+="\\";
  110.   return st;
  111. }
  112.  
  113. CString CNewProj::GetName() {
  114.   return m_projname;
  115. }
  116.  
  117. CString CNewProj::GetPath0() {
  118.   CString st=m_projpath;
  119.   st.Replace('/','\\');
  120.   st+="\\";
  121.   st+=m_projname;
  122.   return st;
  123. }
  124.  
  125. CString CNewProj::GetPath() {
  126.   CString st=GetPath0();
  127.   st+="\\";
  128.   return st;
  129. }
  130.  
  131. LRESULT CNewProj::OnWizardNext() {
  132.   CString st,stp="";
  133.   char tempo[8192];
  134.  
  135.   GetDlgItemText(IDC_projpath,stp);
  136.   strcpy(tempo,stp);
  137.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\'))
  138.     tempo[strlen(tempo)-1]='\0';
  139.   stp=tempo;
  140.  
  141.   // ecrire
  142.   CString strSection       = "DefaultValues";    
  143.   CWinApp* pApp = AfxGetApp();
  144.   pApp->WriteProfileString(strSection,"BasePath",stp);
  145.  
  146.   GetDlgItemText(IDC_projname,st);
  147.   strcpy(tempo,st);
  148.   // caractΦres interdits
  149.   {
  150.     int i;
  151.     char* a=NULL;
  152.     for(i=0;i<9;i++)
  153.       while(a=strchr(tempo,("\\/:*?\"<>|")[i])) 
  154.         *a=' ';
  155.   }
  156.   //
  157.   //while(a=strchr(tempo,' ')) *a='_';      // PAS de _
  158.   SetDlgItemText(IDC_projname,tempo);
  159.  
  160.   // ModifiΘ et sauvable
  161.   GetDlgItemText(IDC_projpath,stp);
  162.   if ((stp.Right(1)!="\\") && (stp.Right(1)!="/"))    // ajouter /
  163.     stp+="\\";
  164.   GetDlgItemText(IDC_projname,st);
  165.   this_CSplitterFrame->SetNewName(stp+st+".whtt");
  166.   //GetDlgItemText(IDC_projpath,st);
  167.   //this_CSplitterFrame->GetActiveDocument()->SetPathName(st);
  168.  
  169.   if (can_click_next)
  170.     return 0;
  171.   else
  172.     return -1;
  173. }
  174.  
  175. void CNewProj::Onbr() 
  176. {
  177.   CString st,spth;
  178.   char pth[256];
  179.   GetDlgItemText(IDC_projpath,spth);
  180.   strcpy(pth,spth);
  181.   st=XSHBrowseForFolder(this->m_hWnd,"Select a path name for mirror",pth);
  182.   if (st.GetLength()>0) {
  183.     if (st.Right(1)=='\\')
  184.       st=st.Left(st.GetLength()-1);
  185.     SetDlgItemText(IDC_projpath,st);
  186.   }
  187.  
  188. }
  189.  
  190. BOOL CNewProj::OnInitDialog() 
  191. {
  192.     CPropertyPage::OnInitDialog();
  193.   SetIcon(httrack_icon,false);
  194.   SetIcon(httrack_icon,true);
  195.   EnableToolTips(true);     // TOOL TIPS
  196.   SetForegroundWindow();   // yop en premier plan!
  197.  
  198.   // disabled
  199.   OnChangeprojname();
  200.  
  201.   // Patcher l'interface pour les Franτais ;-)
  202.   if (LANG_T(-1)) {    // Patcher en franτais
  203.     SetWindowText( LANG(LANG_S10));
  204.     // SetDlgItemText(IDOK,LANG(LANG_NEXT )); // "SUIVANT ->");
  205.     // SetDlgItemText(IDCANCEL,LANG(LANG_QUIT));  // exit 
  206.     SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  207.     SetDlgItemText(IDC_STATIC_basepath,LANG(LANG_S12));
  208.     //SetDlgItemText(IDC_STATIC_updtcontinue,LANG(LANG_S13));
  209.   }
  210.   
  211.   CString strSection       = "DefaultValues";    
  212.   CWinApp* pApp = AfxGetApp();
  213.   CString st;
  214.  
  215.   st = pApp->GetProfileString(strSection, "BasePath");
  216.   if (m_projpath.GetLength()==0) {
  217.     if (st != "")
  218.       SetDlgItemText(IDC_projpath,st);    
  219.     else
  220.       SetDlgItemText(IDC_projpath,LANG(LANG_S20));    
  221.   }
  222.  
  223.   return TRUE;
  224. }
  225.  
  226. void CNewProj::OnChangeprojpath() 
  227. {
  228.   CWaitCursor wait;
  229.   CString st;
  230.   CString old_name;
  231.   char tempo[HTS_URLMAXSIZE*2];
  232.  
  233.   GetDlgItemText(IDC_projname,old_name);
  234.   GetDlgItemText(IDC_projpath,st);
  235.   strcpy(tempo,st);
  236.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\')) {
  237.     tempo[strlen(tempo)-1]='\0';
  238.     //SetDlgItemText(IDC_projpath,tempo);
  239.   }
  240.   strcat(tempo,"\\");
  241.  
  242.   // chargement de la liste
  243.   m_ctl_projname.ResetContent();
  244.   WIN32_FIND_DATA find;
  245.   char  pth[MAX_PATH + 32];
  246.   strcpy(pth,tempo);
  247.   strcat(pth,"*.*");
  248.   HANDLE h = FindFirstFile(pth,&find);
  249.   if (h != INVALID_HANDLE_VALUE) {
  250.     do {
  251.       if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY )
  252.       if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  253.       if (strcmp(find.cFileName,".."))
  254.         if (strcmp(find.cFileName,".")) {
  255.           CString st;
  256.           st=tempo;
  257.           st=st+find.cFileName;
  258.           st=st+"\\hts-cache";
  259.  
  260.           WIN32_FIND_DATA find2;
  261.           HANDLE h2 = FindFirstFile(st,&find2);
  262.           if (h2 != INVALID_HANDLE_VALUE) {
  263.             FindClose(h2);
  264.             m_ctl_projname.InsertString(-1,find.cFileName);
  265.           }
  266.         }
  267.     } while(FindNextFile(h,&find));
  268.     FindClose(h);
  269.   }
  270.  
  271.   // nouveau nom!
  272.   SetDlgItemText(IDC_projname,old_name);
  273.   OnChangeprojname();
  274. }
  275.  
  276.  
  277.  
  278. // ------------------------------------------------------------
  279. // TOOL TIPS
  280. //
  281. // ajouter dans le .cpp:
  282. // remplacer les deux Wid1:: par le nom de la classe::
  283. // dans la message map, ajouter
  284. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  285. // dans initdialog ajouter
  286. // EnableToolTips(true);     // TOOL TIPS
  287. //
  288. // ajouter dans le .h:
  289. // char* GetTip(int id);
  290. // et en generated message map
  291. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  292. BOOL CNewProj::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  293. {
  294.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  295.   UINT nID =pNMHDR->idFrom;
  296.   if (pTTT->uFlags & TTF_IDISHWND)
  297.   {
  298.     // idFrom is actually the HWND of the tool
  299.     nID = ::GetDlgCtrlID((HWND)nID);
  300.     if(nID)
  301.     {
  302.       char* st=GetTip(nID);
  303.       if (st != "") {
  304.         pTTT->lpszText = st;
  305.         pTTT->hinst = AfxGetResourceHandle();
  306.         return(TRUE);
  307.       }
  308.     }
  309.   }
  310.   return(FALSE);
  311. }
  312. char* CNewProj::GetTip(int ID)
  313. {
  314.   switch(ID) {
  315.     case IDC_projname:  return LANG(LANG_S1); break;
  316.     case IDC_projpath:  return LANG(LANG_S2); break;
  317.     //case IDC_projlist:  return LANG(LANG_S3); break;
  318.     case IDC_br:        return LANG(LANG_S4); break;
  319.     case IDCANCEL:     return LANG(LANG_G20); break; // "Quit WinHTTrack","Quittter WinHTTrack"); break;
  320.     case IDOK:         return LANG(LANG_G23); break; // "Click to continue","Clic pour continuer"); break;
  321.   }
  322.   return "";
  323. }
  324. // TOOL TIPS
  325. // ------------------------------------------------------------
  326.  
  327.  
  328. void CNewProj::OnChangeprojname() 
  329. {
  330.   CString stl;
  331.   GetDlgItemText(IDC_projname,stl);
  332.   Changeprojname(stl);
  333. }
  334.  
  335. void CNewProj::Changeprojname(CString stl) {
  336.   CWaitCursor wait;
  337.   CString st;
  338.   //
  339.   if (stl.GetLength()==0) {
  340.     //m_ctl_idok.ModifyStyle(0,WS_DISABLED);
  341.     SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S30));
  342.     SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11c));
  343.     this_CWizTab->SetWizardButtons(PSWIZB_BACK);
  344.     can_click_next=FALSE;
  345.   } else {
  346.     char tempo[HTS_URLMAXSIZE*2];
  347.     GetDlgItemText(IDC_projpath,st);
  348.     strcpy(tempo,st);
  349.     strcat(tempo,"/");
  350.     strcat(tempo,stl);
  351.     strcat(tempo,"/");
  352.     if (fexist(fconcat(tempo,"hts-cache/winprofile.ini"))) {    // un cache est prΘsent
  353.       if (fsize(fconcat(tempo,"hts-cache/winprofile.ini"))>0) {   // taille log contr⌠le>0
  354.         CString strSection       = "OptionsValues";
  355.         CString st = MyGetProfileString(fconcat(tempo,"hts-cache/winprofile.ini"),strSection,"CurrentUrl");
  356.         //
  357.         SetDlgItemText(IDC_STATIC_comments,st);
  358.         SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11b));
  359.       } else {
  360.         SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S31));
  361.         SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  362.       }
  363.     } else {
  364.       SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S31));
  365.       SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  366.     }
  367.     //m_ctl_idok.ModifyStyle(WS_DISABLED,0);
  368.     //if (!can_click_next)
  369.       this_CWizTab->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);
  370.     can_click_next=TRUE;
  371.   }
  372.   //m_ctl_idok.RedrawWindow();
  373. }
  374.  
  375.  
  376. // help
  377. // Appel aide
  378. BOOL CNewProj::OnHelpInfo2() {
  379.   return OnHelpInfo(NULL);
  380. }
  381.  
  382. BOOL CNewProj::OnHelpInfo(HELPINFO* dummy) 
  383. {
  384.   //return CPropertyPage::OnHelpInfo(pHelpInfo);
  385.   //AfxGetApp()->WinHelp(0,HELP_FINDER);    // Index du fichier Hlp
  386.   HtsHelper->Help("step1.html");
  387.   //HtsHelper->Help();
  388.   return true;
  389. }
  390.  
  391.  
  392. extern HWND App_Main_HWND;
  393. int CNewProj::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  394. {
  395.   //lpCreateStruct->hwndParent=AfxGetApp()->GetMainWnd()->m_hWnd;
  396.   lpCreateStruct->hwndParent=App_Main_HWND;
  397.     if (CPropertyPage::OnCreate(lpCreateStruct) == -1)
  398.         return -1;
  399.     
  400.   // Drag&Drop
  401.   drag=new CEasyDropTarget(this);
  402.   if (drag->IsRegistered()) {
  403.     drag->SetTextCallback(wm_CEasyDropTargetCallback);
  404.   }
  405.     
  406.     return 0;
  407. }
  408.  
  409. // Message from CEasyDropTarget
  410. LRESULT CNewProj::DragDropText(WPARAM wParam,LPARAM lParam) {
  411.   if (lParam) {
  412.     CString st=*((CString*) lParam);
  413.     CLIPFORMAT cfFormat=wParam;
  414.     if (cfFormat==CF_HDROP) {
  415.       if (st.Right(5).CompareNoCase(".whtt")==0)
  416.         st=st.Left(st.GetLength()-5);
  417.       if(st.GetLength()<256) {
  418.         char s[256];
  419.         strcpy(s,st);
  420.         if (!fexist(s)) {
  421.           if (st.Find('\n')<0) {
  422.             int pos=st.ReverseFind('\\');
  423.             SetDlgItemText(IDC_projpath,st.Mid(0,pos));
  424.             SetDlgItemText(IDC_projname,st.Mid(pos+1));
  425.             //
  426.             OnChangeprojpath();
  427.             OnChangeprojname();
  428.           } else
  429.             AfxMessageBox(LANG(LANG_DIAL3),MB_SYSTEMMODAL);
  430.         } else
  431.           AfxMessageBox(LANG(LANG_DIAL4),MB_SYSTEMMODAL);
  432.       }
  433.     } else
  434.       AfxMessageBox(LANG(LANG_DIAL5),MB_SYSTEMMODAL);
  435.   }
  436.   return 0;
  437. }
  438.  
  439.  
  440. void CNewProj::OnSelchangeprojname() 
  441. {
  442.   CString stl;
  443.   int r;
  444.   if ((r=m_ctl_projname.GetCurSel()) != CB_ERR) {
  445.     m_ctl_projname.GetLBText(r,stl);
  446.   } else
  447.     GetDlgItemText(IDC_projname,stl);
  448.   Changeprojname(stl);
  449. }
  450.  
  451. BOOL CNewProj::OnSetActive( ) {
  452.   //this_CWizTab->SetWizardButtons(PSWIZB_BACK);
  453.  
  454.   WHTT_LOCATION("NewProj");
  455.   //if (!can_click_next) {
  456.   // structure visible
  457.   CString st;
  458.   GetDlgItemText(IDC_projpath,st);    
  459.   this_DirTreeView->EnsureVisible(st+"\\index.html");
  460.   this_CWizTab->SetDlgItemText(IDCANCEL,LANG_CANCEL);
  461.   //} else
  462.   //this_CWizTab->PressButton(PSBTN_NEXT);
  463.   
  464.   return 1;
  465. }
  466.  
  467. BOOL CNewProj::OnQueryCancel( ) {
  468.   this_CSplitterFrame->SetNewView(0,1,RUNTIME_CLASS(CDialogContainer));
  469.   return 0;
  470. }
  471.  
  472. BOOL CNewProj::OnKillActive( ) {
  473.   CString st;
  474.   char tempo[HTS_URLMAXSIZE*2];
  475.   GetDlgItemText(IDC_projpath,st);
  476.   strcpy(tempo,st);
  477.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\')) {
  478.     tempo[strlen(tempo)-1]='\0';
  479.     SetDlgItemText(IDC_projpath,tempo);
  480.   }
  481.  
  482.   UpdateData(TRUE);         // DoDataExchange
  483.  
  484.   // crΘer structure
  485.   {
  486.     char dest[HTS_URLMAXSIZE*2];
  487.     int i=0;
  488.     strcpy(dest,GetPath()+"hts-cache\\");
  489.     {
  490.       char* a;
  491.       while(a=strchr(dest,'\\')) *a='/';
  492.       structcheck(dest);
  493.     }
  494.   }
  495.  
  496.   CShellApp_app->end_path=dialog0->GetBasePath();
  497.   CShellApp_app->end_path_complete=dialog0->GetPath();
  498.   Build_TopIndex(FALSE);
  499.  
  500.   // structure visible
  501.   this_DirTreeView->EnsureVisible(GetPath()+"hts-cache");
  502.  
  503.   // charger prΘfs
  504.   dialog1->OnChangepathlog();
  505.  
  506.   return 1;
  507. }
  508.  
  509.  
  510.